package main

import (
	"encoding/json"
	"fmt"
)

type Monster struct {
	Name     string
	Age      int
	Birthday string
	Sal      float64
	Skill    string
}

func testStruct() {
	monster := Monster{
		Name:     "牛魔王",
		Age:      12,
		Birthday: "2001-11-11",
		Sal:      5000.2,
		Skill:    "niu",
	}

	data, err := json.Marshal(&monster)

	if err != nil {
		fmt.Printf("序列化错误=%v", err)
	}

	fmt.Printf("序列化结果=%v", string(data))
	fmt.Println()

	var monster2 Monster
	err = json.Unmarshal(data, &monster2)
	if err != nil {
		fmt.Printf("unmarshal err=%v\n", err)
	}

	fmt.Printf("反序列化后 monster=%v monster.Name=%v \n", monster, monster.Name)
}

func main() {
	testStruct()

}
